package com.Mt.Mager.Contorller;

import com.Mt.Dto.Dto;
import com.Mt.Service.Mt_CommodityService;
import com.Mt.Utils.DtoUtil;
import com.Mt.pojo.Mt_CommodityAdmin;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RequestMapping("CommodityAdmin")
@RestController
public class Mt_CommodityAdminController {

    @Reference
    private Mt_CommodityService mt_commodityService;

    @GetMapping("Page/{index}")
    public Dto pagea(@PathVariable("index") int index){
        return DtoUtil.returnSuccessData(mt_commodityService.pageAll(index));
        //return new Dto(32132,"通过",userService.page(index));
    }

    @GetMapping("like/{cName}/{index}")
    public Dto namePage(@PathVariable String cName,@PathVariable int index){
        return DtoUtil.returnSuccessData(mt_commodityService.like(cName,index));
    }

    @GetMapping("del/{id}")
    public Dto del(@PathVariable int id){
        int row = mt_commodityService.del(id);
        if(row>0){
            return DtoUtil.returnSuccess();
        }else{
            return DtoUtil.returnError(5001,"删除失败");
        }

    }

    @GetMapping("selId/{id}")
    public Dto selId(@PathVariable int id){
        return DtoUtil.returnSuccessData(mt_commodityService.selId(id));
        }


    @PostMapping("add")
    public Dto add(@RequestBody Mt_CommodityAdmin commodityAdmin){

        commodityAdmin.setCommodity_img("imageView2/2/w/400/h/400");
        commodityAdmin.setCommodity_specification(0);

        int row = mt_commodityService.addCommodity(commodityAdmin);
        if(row>0){
            return DtoUtil.returnSuccess();
        }else{
            return DtoUtil.returnError(2021,"添加失败");
        }

    }
}
